package com.useeinfo.oa.modules.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.security.enums.DeviceType;
import com.useeinfo.oa.modules.security.enums.Surroundings;
import org.apache.commons.lang.StringUtils;

import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "app_version")
public class AppVersion extends SuperClassEntity<AppVersion> {

    /**
     * 版本号
     */
    private String version;
    /**
     * 更新描述
     */
    private String updateSub;
    /**
     * app下载地址
     */
    private String appUrl;
    /**
     * app类型  具体见DeviceType枚举
     */
    private String deviceType;
    /**
     * 环境     测试环境/生产环境   具体见Surroundings枚举
     */
    private String surroundings;
    private String versionCode;


    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("version", StringConverters.null2String(getVersion()));
        jsonObject.put("updateSub", StringConverters.null2String(getUpdateSub()));
        jsonObject.put("appUrl", StringConverters.null2String(getAppUrl()));
        jsonObject.put("versionCode", StringConverters.null2String(getVersionCode()));

        jsonObject.put("deviceType", StringConverters.null2String(getDeviceType()));
        jsonObject.put("surroundings", StringConverters.null2String(getSurroundings()));
        jsonObject.put("surroundingsName", StringUtils.isBlank(getSurroundings()) ? "" : Surroundings.valueOf(getSurroundings()).getName());
        jsonObject.put("deviceTypeName", StringUtils.isBlank(getDeviceType()) ? "" : DeviceType.valueOf(getDeviceType()).getName());

        return jsonObject;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getUpdateSub() {
        return updateSub;
    }

    public void setUpdateSub(String updateSub) {
        this.updateSub = updateSub;
    }

    public String getAppUrl() {
        return appUrl;
    }

    public void setAppUrl(String appUrl) {
        this.appUrl = appUrl;
    }

    public String getDeviceType() {
        return deviceType;
    }

    public void setDeviceType(String deviceType) {
        this.deviceType = deviceType;
    }

    public String getSurroundings() {
        return surroundings;
    }

    public void setSurroundings(String surroundings) {
        this.surroundings = surroundings;
    }

    public String getVersionCode() {
        return versionCode;
    }

    public void setVersionCode(String versionCode) {
        this.versionCode = versionCode;
    }
}
